package com.study.seckill.web.api;

import com.study.exceptions.CourseException;
import com.study.exceptions.CourseSeckillException;
import com.study.exceptions.CourseSeckillOrderException;
import com.study.exceptions.UserException;
import com.study.util.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName: ExceptionLinsterHandler
 * @Author: wYin
 * @Date: 2022/3/14 10:07
 */
//@RestControllerAdvice
@Slf4j
public class ExceptionLinsterHandler {
    @ExceptionHandler(UserException.class)
    public ResponseResult<String> userExceptionHandler(UserException e){
        log.error(e.getMessage());
        return new ResponseResult<>(500,"ex",e.getMessage());
    }
    @ExceptionHandler(CourseException.class)
    public ResponseResult<String> courseExceptionHandler(CourseException e){
        log.error(e.getMessage());
        return new ResponseResult<>(500,"ex",e.getMessage());
    }
    @ExceptionHandler(CourseSeckillException.class)
    public ResponseResult<String> courseSeckillExceptionHandler(CourseSeckillException e){
        log.error(e.getMessage());
        return new ResponseResult<>(500,"ex",e.getMessage());
    }
    @ExceptionHandler(CourseSeckillOrderException.class)
    public ResponseResult<String> courseSeckillOrderExceptionHandler(CourseSeckillOrderException e){
        log.error(e.getMessage());
        return new ResponseResult<>(500,"ex",e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public ResponseResult<String> exceptionHandler(Exception e){
        log.error(e.getMessage());
        return new ResponseResult<>(500,"ex",e.getCause().toString());
    }
}
